<?php
//  +----------------------------------------------------------------------
//  | Copyright (c) 2015-2025 http://www.hdphp.cn All rights reserved.
//  | Licensed ( http://www.hdphp.cn/licenses/ )
//  | Author: Jack <sophia2152@qq.com>
//  | 官方网址: http://www.hdphp.cn
//  | 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
//  | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
//  +----------------------------------------------------------------------

use think\facade\Route;
use think\facade\Config;
use think\Response;
use app\http\middleware\AllowOriginMiddleware;
use app\http\middleware\StationOpenMiddleware;
use app\http\middleware\api\AuthTokenMiddleware;

/**
 * 后台管理路由配置
 */
Route::group('api', function () {

//    Route::any('wechat/serve', 'v1.wechat.WechatController/serve');//公众号服务
//    Route::any('wechat/miniServe', 'v1.wechat.WechatController/miniServe');//小程序服务
//    Route::any('work/serve', 'v1.wechat.WechatController/work');//公众号服务
//    Route::any('wechat/notify', 'v1.wechat.WechatController/notify');//公众号支付回调
//    Route::any('routine/notify', 'v1.wechat.AuthController/notify');//小程序支付回调
//    Route::any('pay/notify/:type', 'v1.PayController/notify');//支付回调
//    Route::any('city_delivery/notify', 'v1.CityDeliveryController/notify');//UU、达达回调
//    // 图形验证码
//    Route::get('ajcaptcha', 'v1.LoginController/ajcaptcha')->name('ajcaptcha');
//    //图形验证码
//    Route::post('ajcheck', 'v1.LoginController/ajcheck')->name('ajcheck');

    // 统计代码
    Route::post('get_script', 'v1.PublicController/getScript');

    Route::get('get_copyright', 'v1.PublicController/getCopyright');//获取版权

    /**
     * 无需授权的接口
     */
    Route::group(function () {

        Route::get('index', 'v1.TestController/index');

        // 获取网站配置
        Route::get('site_config', 'v1.PublicController/getSiteConfig')->name('getSiteConfig');

    })->middleware(StationOpenMiddleware::class);;

    /**
     * 授权不通过,不会抛出异常继续执行
     */
    Route::group(function () {

    })->middleware(StationOpenMiddleware::class)->middleware(AuthTokenMiddleware::class, false);


    /**
     * diy相关
     */
    Route::group('diy', function () {

        //无需登录接口
        Route::group(function () {
            Route::get('get_diy/[:id]', 'v1.PublicController/getDiy');//DIY接口
            Route::get('diy_version/[:id]', 'v1.PublicController/getDiyVersion');//DIY版本接口
        });

        //未授权接口---不会抛异常
        Route::group(function () {

            Route::get('user_info', 'v1.diy.Diy/userInfo')->name('diyUserInfo');//diy用户信息
            Route::get('video_list', 'v1.diy.Diy/videoList')->name('diyVideoList');//diy短视频列表
            Route::get('newcomer_list', 'v1.diy.Diy/newcomerList')->name('diyNewcomerList');//diy新人专享商品列表

        })->middleware(AuthTokenMiddleware::class, false);

        //需要授权接口
        Route::group(function () {

        })->middleware(AuthTokenMiddleware::class, true);

    })->middleware(StationOpenMiddleware::class);


    /**
     * miss 路由
     */
    Route::miss(function () {
        if (app()->request->isOptions()) {
            $header = Config::get('cookie.header');
            $header['Access-Control-Allow-Origin'] = app()->request->header('origin');
            return Response::create('ok')->code(200)->header($header);
        }
        return Response::create()->code(404);
    });

})->prefix('api.')->middleware(AllowOriginMiddleware::class)->middleware(StationOpenMiddleware::class);
